package com.cw.jeeyt.service.converter.system;

import java.util.ArrayList;
import java.util.List;

import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
import com.cw.jeeyt.service.bo.system.SystemAttachBo;
import com.cw.jeeyt.dao.model.system.SystemAttachDo;
import com.cw.lang.common.utils.CollectionUtil;

/**
 * 附件管理转换类
 *
 * @author chenw
 * @date 2019-03-10 13:04:25
 */
public class SystemAttachConverter {

    /**
     * do转bo
     *
     * @param model
     * @return
     */
    public static SystemAttachBo do2Bo(SystemAttachDo model) {
        if (model == null) {
            return null;
        }
        SystemAttachBo bo = new SystemAttachBo();
        bo.setId(model.getId());
        bo.setFileName(model.getFileName());
        bo.setContentType(model.getContentType());
        bo.setContent(model.getContent());
        bo.setFileType(model.getFileType());
        bo.setFileSize(model.getFileSize());
        bo.setFileDir(model.getFileDir());
        bo.setOriginalFileName(model.getOriginalFileName());
        bo.setCreateBy(model.getCreateBy());
        bo.setCreateDate(model.getCreateDate());
        bo.setUpdateBy(model.getUpdateBy());
        bo.setUpdateDate(model.getUpdateDate());
        return bo;
    }

    /**
     * bo转do
     *
     * @param bo
     * @return
     */
    public static SystemAttachDo bo2Do(SystemAttachBo bo) {
        if (bo == null) {
            return null;
        }
        SystemAttachDo model = new SystemAttachDo();
        model.setId(bo.getId());
        model.setFileName(bo.getFileName());
        model.setContentType(bo.getContentType());
        model.setContent(bo.getContent());
        model.setFileType(bo.getFileType());
        model.setFileSize(bo.getFileSize());
        model.setFileDir(bo.getFileDir());
        model.setOriginalFileName(bo.getOriginalFileName());
        model.setCreateBy(bo.getCreateBy());
        model.setCreateDate(bo.getCreateDate());
        model.setUpdateBy(bo.getUpdateBy());
        model.setUpdateDate(bo.getUpdateDate());
        return model;
    }

    /**
     * doList转boList
     *
     * @param doList
     * @return
     */
    public static List<SystemAttachBo> doList2BoList(List<SystemAttachDo> doList) {
        if (CollectionUtil.isEmpty(doList)) {
            return new ArrayList<>();
        }
        return Lists.newArrayList(Iterators.transform(doList.iterator(), SystemAttachConverter::do2Bo));
    }

    /**
     * boList转doList
     *
     * @param boList
     * @return
     */
    public static List<SystemAttachDo> boList2DoList(List<SystemAttachBo> boList) {
        if (CollectionUtil.isEmpty(boList)) {
            return new ArrayList<>();
        }
        return Lists.newArrayList(Iterators.transform(boList.iterator(), SystemAttachConverter::bo2Do));
    }
}